unit utils;

interface
uses graph, crt, constant,TPDate,draw;
  function ReadChar: Char;
  procedure Beep;
  procedure SelectItem(var CurrentElement: integer);
  procedure UnSelectItem(var CurrentElement: integer);
  procedure IncDec(CurrentElement: integer;bool: boolean);
  procedure IncDecSS(CurrentElement: integer;bool: boolean);
  procedure OutCurrentTime(var NewTime,OldTime: longint);
implementation

procedure SelectItem(var CurrentElement: integer);
begin
  SetColor(LightGreen);
  with DrawMemory[CurrentElement] do
   Rectangle(x1,y1,x2,y2)
end;

procedure UnSelectItem(var CurrentElement: integer);
begin
  SetColor(lightBlue);
  with DrawMemory[CurrentElement] do
    Rectangle(x1,y1,x2,y2)
end;

procedure IncDecSS(CurrentElement: integer;bool: boolean);
var st: string[4];
begin
 with DrawMemory[CurrentElement] do
  begin
   SetFillStyle(0, LightGreen);
   FloodFill(x1+5,y1+5,LightGreen);
   SetColor(LightRed);
    if CurrentElement=12 then
    begin
     if bool
     then
       Inc(stepValue)
     else
       Dec(stepValue);
     str(stepValue,st);
     end;
   if CurrentElement=13 then
    begin
     if bool
     then
        Inc(speedValue)
     else
         Dec(speedValue);
      str(speedValue,st);
    end;
   OutTextXY(x1+15,y1+dy,'Dec='+st);
  end;
end;

procedure IncDec(CurrentElement: integer;bool: boolean);
var st: string[4];
begin
 with Registrs[CurrentElement] do
  begin
    if (CurrentElement= 7 ) or  (CurrentElement= 9 ) then
    begin
      SetFillStyle(0, LightGreen);
      FloodFill(x,y,LightGreen);
      SetColor(LightRed);
      if bool
      then
        Inc(value^,stepValue)
      else
        Dec(value^,stepValue);
      str(value^,st);
      OutTextXY(x,y,'Hex='+WriteHexWord(value^));
      OutTextXY(x,y+dy,'Dec='+st);
    end
    else
      Beep;
  end;
end;

function ReadChar: Char;
var
  Ch: Char;
begin
 Ch := ReadKey;
 if Ch = #0 then
  case readkey of
    #27: Ch := CEsc;      {Esc}
    #43: Ch := CPlus;     {+}
    #44: Ch := CMinus;    {-}
    #45: Ch := CExit;     {Alt-X}
    #9 : Ch := CTab;      {Tab}
    #62: Ch := CNewValue;  {F4}
    #67: Ch := CF9;        {F9}
    #65: Ch := CF7;        {F7}
    #102: Ch := CCtrlF9;  {Ctrl-F9}
  end;
 ReadChar := Ch;
end;

procedure Beep;
begin
 Sound(500);
 Delay(25);
 NoSound;
end;

procedure OutCurrentTime(var NewTime,OldTime: longint);
begin
 NewTime:=Trunc(meml[$40:$6c]/18.2065);
 if NewTime<>OldTime then
  begin
   if OldTime<>0 then
    begin
     SetColor(0);
     OutTextXY(570, 460, TimeToTimeString('hh:mm:ss', OldTime));
     SetColor(10);
    end;
   OldTime:=NewTime;
   OutTextXY(570, 460, TimeToTimeString('hh:mm:ss', NewTime));
  end;
end;
end.